'use strict';
const {getDefaultModelConfig} = require("../../utils/common");
// 每日采购单
module.exports = app => {
    const { STRING, INTEGER, BIGINT, DATE, TEXT } = app.Sequelize;
    const DailyMenu = app.model.define(
        'DailyMenu',
        {
            id: { type: BIGINT, primaryKey: true, autoIncrement: true },
            menu_date: { type: DATE, allowNull: false, comment: '菜单日期' },
            title: { type: STRING(255), allowNull: false, comment: '菜单标题' },
            description: { type: TEXT, comment: '菜单描述' },
            monthly_bidding_id: { type: BIGINT, allowNull: false, comment: '月度比价ID' },
            supplier_id: { type: BIGINT, allowNull: false, comment: '供应商ID' },
            purchaser_id: { type: BIGINT, allowNull: false, comment: '采购员ID' },
            status: { type: INTEGER, defaultValue: 1, comment: '状态 1:待采购 2:采购中 3:已收货 4:已完成' },
            ...getDefaultModelConfig(app)
        },
        {
            tableName: 'daily_menu',
            timestamps: true,
            createdAt: 'create_time',
            updatedAt: 'update_time'
        }
    );
    
    // 定义关联关系
    DailyMenu.associate = function() {
        // 与供应商的关联
        DailyMenu.belongsTo(app.model.Business.Supplier, {
            foreignKey: 'supplier_id',
            as: 'supplier'
        });
        
        // 与采购员的关联
        DailyMenu.belongsTo(app.model.Business.Purchaser, {
            foreignKey: 'purchaser_id',
            as: 'purchaser'
        });
        
        // 与月度比价的关联
        DailyMenu.belongsTo(app.model.Business.MonthlyBidding, {
            foreignKey: 'monthly_bidding_id',
            as: 'monthlyBidding'
        });
    };
    
    return DailyMenu;
};
 